package com.example.design.websocket;

import com.alibaba.nacos.common.utils.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WebSocketTestController {
    /**
     * 服务端给指定客户端推送数据
     * @param userId
     * @param message
     */
    @GetMapping("/pushWebsocketMsg")
    public void pushWebsocketMsg(Integer userId, String message) {
        if (userId ==null) {
            userId = 1;
        }
        if (StringUtils.isEmpty(message)) {
            message = "aaa";
        }
        WebSocketSever.sendMessageByUser(userId, message);
    }

    @GetMapping("/hello")
    public String hello() {
        return "hello";
    }
}
